﻿@page
@model FytSoa.Web.Pages.FytAdmin.Sys.LogModel
@{
    ViewData["Title"] = "系统日志";
    Layout = AdminLayout.Pjax(HttpContext);
}
<div id="container">
    <div class="list-wall">
        <div class="layui-form list-search" style="margin-top:10px;">
            <div class="layui-inline">
                <input class="layui-input" id="key" autocomplete="off" placeholder="请输入关键字查询">
            </div>
            <div class="layui-inline lay-time-icon">
                <input class="layui-input" id="times" autocomplete="off" placeholder="时间区间"><i class="layui-icon layui-icon-date"></i>
            </div>
            <button type="button" class="layui-btn layui-btn-sm" data-type="toolSearch"><i class="layui-icon layui-icon-search"></i> 搜索</button>
        </div>
        <table class="layui-hide" id="tablist" lay-filter="tool"></table>
    </div>
    <script type="text/html" id="toolbar">
        <div class="layui-btn-container">
            <button type="button" class="layui-btn layui-btn-sm" lay-event="toolDel"><i class="layui-icon"></i> 删除</button>
        </div>
    </script>
    <script>
        layui.config({
            base: '/themes/js/modules/'
        }).use(['table', 'layer', 'jquery', 'laydate', 'common'],
            function () {
                var table = layui.table,
                    layer = layui.layer,
                    $ = layui.jquery,
                    os = layui.common,
                    laydate = layui.laydate;
                laydate.render({
                    elem: '#times'
                    , theme: '#393D49'
                    , format:'yyyy/MM/dd'
                    , range: true
                });
                table.render({
                    toolbar: '#toolbar',
                    elem: '#tablist',
                    url: '/api/log/getpages',
                    cols: [
                        [
                            { type: 'checkbox', fixed: 'left' },
                            { field: 'loginName', title: '登录账号', sort: true, fixed: 'left' },
                            { field: 'departName', title: '归属部门' },
                            { field: 'optionTable', title: '操作表' },
                            { field: 'ip', title: 'IP' },
                            { field: 'addTime', title: '登录时间' }
                        ]
                    ],
                    page: { limits: [10, 20, 50, 100, 500, 1000, 5000, 10000], groups:8 },
                    id: 'tables'
                });

                var guid = '', active = {
                    reload: function () {
                        table.reload('tables',
                            {
                                page: {
                                    curr: 1
                                },
                                where: {
                                    key: $("#key").val(),
                                    time: $("#times").val()
                                }
                            });
                    },
                    toolSearch: function () {
                        active.reload();
                    },
                    toolDel: function () {
                        var checkStatus = table.checkStatus('tables')
                            , data = checkStatus.data;
                        if (data.length === 0) {
                            os.error("请选择要删除的项目~");
                            return;
                        }
                        var str = '';
                        $.each(data, function (i, item) {
                            str += item.guid + ",";
                        });
                        layer.confirm('确定要执行批量删除吗？', function (index) {
                            layer.close(index);
                            var loadindex = layer.load(1, {
                                shade: [0.1, '#000']
                            });
                            os.ajax('api/log/delete/', { parm: str }, function (res) {
                                layer.close(loadindex);
                                if (res.statusCode === 200) {
                                    active.reload();
                                    os.success('删除成功！');
                                } else {
                                    os.error(res.message);
                                }
                            });
                        });

                    }
                };
                table.on('toolbar(tool)', function (obj) {
                    active[obj.event] ? active[obj.event].call(this) : '';
                });
                $('.list-search .layui-btn').on('click', function () {
                    var type = $(this).data('type');
                    active[type] ? active[type].call(this) : '';
                });
            });
    </script>
</div>
